#include <iostream>
#include <vector>

using namespace std;

int numSquares(int n) {
    int m = sqrt(n);
    vector<int> dp(n + 1);

    for (int j = 1; j <= n; ++j)
        dp[j] = 0x3f3f3f3f;

    for (int i = 1; i <= m; ++i)
    {
        for (int j = i * i; j <= n; ++j)
        {
            dp[j] = min(dp[j], dp[j - i * i] + 1);
        }
    }

    dp[n] = (dp[n] == 0x3f3f3f3f) ? 0 : dp[n];
    return dp[n];
}

int main()
{
    numSquares(12);
	return 0;
}